#include "FileDebug.h"
#include <BAUTILS.H>

FileDebug::FileDebug()
{
	fs.Connect();
	
	_LIT(filename, "c:\\debug.txt");
	BaflUtils::EnsurePathExistsL(fs, filename);
	User::LeaveIfError(rf.Replace(fs, filename, EFileWrite));
}

FileDebug::~FileDebug()
{
	rf.Close();
	fs.Close();		
}

void FileDebug::Write(const TDesC8& title, const TDesC8& msg)
{
	rf.Write(title);
	rf.Write(_L8("\r\n"));
	rf.Write(msg);
	rf.Write(_L8("\r\n\r\n"));
	rf.Flush();
}

void FileDebug::Write(const TDesC& title, const TDesC& msg)
{
	{
    HBufC8* text = HBufC8::NewLC(title.Length());
    text->Des().Copy(title);
	rf.Write(*text);
	rf.Write(_L8("\r\n"));
    CleanupStack::PopAndDestroy(text);
	}
    {
    HBufC8* str = HBufC8::NewLC(msg.Length());
    str->Des().Copy(msg);
	rf.Write(*str);
	rf.Write(_L8("\r\n\r\n"));
    CleanupStack::PopAndDestroy(str);
    }
	rf.Flush();
}